package com.ruoyi.web.controller.biz;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.valid.ValidInsertGroup;
import com.ruoyi.common.valid.ValidUpdateGroup;
import com.ruoyi.system.domain.BsStrategy;
import com.ruoyi.system.domain.ro.BsStrategyRO;
import com.ruoyi.system.domain.vo.BsStrategyVO;
import com.ruoyi.system.service.IBsStrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 攻略游记
 *
 * @author ruoyi
 * @date 2023-11-25
 */
@Validated
@RequiredArgsConstructor
@Api(tags = "游客端-攻略游记")
@RestController
@RequestMapping("/customer/strategy")
public class BsStrategyYoukeController extends BaseController {

    private final IBsStrategyService iBsStrategyService;

    /**
     * 查询攻略游记列表
     * 1.关注人发布的-攻略游记列表-按审核通过时间排序
     * 2.推荐-攻略列表（按收藏数排序的-攻略游记列表）
     * 3.按审核时间排序的-攻略游记列表
     * 4.当前登录人点赞的-攻略游记列表-按审核通过时间排序的
     * 5.当前登录人收藏的-攻略游记列表-按审核通过时间排序的
     */
    @ApiOperation(value = "攻略游记-攻略游记列表", tags = {"游客端-攻略游记"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scene", value = "列表场景id:     " +
                    "     * 1.攻略-关注-关注人发布的-攻略游记列表-按审核通过时间排序\n" +
                    "     * 2.攻略-推荐-攻略列表（按收藏数排序的-攻略游记列表）\n" +
                    "     * 3.攻略-最新-按审核时间排序的-攻略游记列表\n" +
                    "     * 4.我的-点赞-当前登录人点赞的-攻略游记列表-按审核通过时间排序的\n" +
                    "     * 5.我的-收藏-当前登录人收藏的-攻略游记列表-按审核通过时间排序的\n" +
                    "     * 6.我的-发布-当前登录人我的页面-发布按钮-按创建时间排序的"
            ),
            @ApiImplicitParam(name = "auditStatus", value = "审核状态 0 已认证/待审核/审核中 1审核通过 2审核拒绝 详见字典strategy_audit_status"),
            @ApiImplicitParam(name = "title", value = "按攻略游记标题搜索,仅支持scene:1,2,3"),
            @ApiImplicitParam(name = "pageNum", value = "分页参数：第几页"),
            @ApiImplicitParam(name = "pageSize", value = "分页参数：每页条数"),
    })
    @GetMapping("/list")
    public Result<TableDataInfo<BsStrategy>> list(@RequestParam() String scene, @RequestParam(required = false) String auditStatus, @RequestParam(required = false) String title) {
        startPage();
        List<BsStrategy> list = iBsStrategyService.queryListByScene(scene, auditStatus, title);
        return Result.success(getDataTable(list));
    }

    @ApiOperation(value = "攻略游记-攻略游记详情(包含作者信息、当前登录人是否关注作者、点赞收藏评论汇总信息)", tags = {"游客端-攻略游记"})
    @GetMapping("/{id}")
    public Result<BsStrategyVO> getInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable Long id) {
        return Result.success(iBsStrategyService.queryInfoAndAuthorById(id));
    }

    /**
     * 新增攻略游记
     */
    @ApiOperation(value = "攻略游记-新增攻略游记", tags = {"游客端-攻略游记"})
    @Log(title = "新增攻略游记", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public Result<?> add(@Validated(ValidInsertGroup.class) @RequestBody BsStrategyRO bo) {
        return Result.toResult(iBsStrategyService.insertByBo(bo));
    }

    /**
     * 修改攻略游记
     */
    @ApiOperation(value = "攻略游记-修改攻略游记", tags = {"游客端-攻略游记"})
    @Log(title = "修改攻略游记", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public Result<?> edit(@Validated(ValidUpdateGroup.class) @RequestBody BsStrategyRO bo) {
        return Result.toResult(iBsStrategyService.updateByBo(bo));
    }

    /**
     * 删除攻略游记
     *
     * @param ids 主键串
     */
    @ApiOperation(value = "攻略游记-删除攻略游记", tags = {"游客端-攻略游记"})
    @Log(title = "删除攻略游记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result<?> remove(@NotEmpty(message = "主键不能为空")
                            @PathVariable Long[] ids) {
        return Result.toResult(iBsStrategyService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
